package Main;

import java.io.InputStream;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import Common.CRes;
import Data.DataEFrame;
import Data.DataEImage;
import Data.DataEffectMap;
import Data.DataGame;
import Data.DataItemMap;

public class Map {
	
	private int width,height;
	
	public Map()
	{
		DataGame.load();//load data 
		this.width=DataGame.ALL_MAP_DATA[0].w;
		this.height=DataGame.ALL_MAP_DATA[0].h;
		
	}
	public void loadMap(int idMap, int w, int h) 
	{  

		this.width=DataGame.ALL_MAP_DATA[idMap].w;
		this.height=DataGame.ALL_MAP_DATA[idMap].h;
	}
	//get width map
	public int GetWidth()
	{
		return this.width;
	}
	//get height map
	public int GetHeight()
	{
		return this.width;
	}
	int seque=0;
	public void update()
	{
		
		seque++;
		
	}
	public void paint(Graphics g) 
	{
		g.setColor(0x1e90ff);
		g.fillRect(0, 0, CCanvas.w, CCanvas.h);
		for(int i=0;i<DataGame.ALL_MAP_DATA[0].allBkgMap.size();i++)
		{
			DataItemMap data=(DataItemMap) DataGame.ALL_MAP_DATA[0].allBkgMap.elementAt(i);
			g.drawImage(DataGame.LoadImage(data.idSmallImage) , data.x, data.y, 0);
			
			for(int j=0;j<DataGame.ALL_MAP_DATA[0].allEffect.size();j++)
			{
				DataEffectMap effectMap=(DataEffectMap) DataGame.ALL_MAP_DATA[0].allEffect.elementAt(j);
				PaintEffect(g,effectMap);
			}
			
		}		
	}	
	
	private void PaintEffect(Graphics g,DataEffectMap effect)
	{
		 int index = effect.id ;
//         for(int i=0;i< DataGame.Effects[index].sequences.size();i++)
//         {
//        	
//        	 Integer sequence =(Integer) DataGame.Effects[index].sequences.elementAt(i);
//			 int idSequence=sequence.intValue();
			 if(seque<DataGame.Effects[index].frames.size())
			 {
				 DataEFrame frames=(DataEFrame) DataGame.Effects[index].frames.elementAt(seque);
	             int countImage = frames.eImages.size();

	             for (int j = 0; j < countImage; j++)
	             {
	                 DataEImage eImage =(DataEImage) frames.eImages.elementAt(j);
	                 g.drawImage(DataGame.LoadImage(eImage.smallID), effect.x + eImage.dx, effect.y + eImage.dy,0);
	             }  	           
			 }
			 
			 else
			 {
				 seque=0;
			 }
			
//         }		
	}
}
